package com.sc.nft.dao;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.sc.nft.entity.DaoSchoolChildMaterial;
import com.sc.nft.entity.dto.*;
import com.sc.nft.entity.vo.DaoSchoolChildMaterialNotPageAdminVO;
import com.sc.nft.entity.vo.DaoSchoolChildMaterialPageAdminVO;
import com.sc.nft.entity.vo.DaoSchoolChildMaterialPageVO;
import com.sc.nft.mapper.DaoSchoolChildMaterialMapper;
import com.sc.nft.pool.SysMemberPool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * 素材表与子集关联表(DaoSchoolChildMaterial)表Dao层
 *
 * @author makejava
 * @since 2023-03-15 18:07:43
 */
@Slf4j
@Repository
public class DaoSchoolChildMaterialDao extends ServiceImpl<DaoSchoolChildMaterialMapper, DaoSchoolChildMaterial> {

    /**
     * 获取关联的所有素材
     *
     * @param pageRequest
     * @return
     */
    public Page<DaoSchoolChildMaterialPageAdminVO> pageAdmin(DaoSchoolChildMaterialPageAdminDTO pageRequest) {
        return baseMapper.pageAdmin(pageRequest.toMp(), pageRequest);
    }

    /**
     * 删除关联
     *
     * @param id
     * @return
     */
    public Boolean deleteById(Long id) {
        return SqlHelper.retBool(baseMapper.deleteById(id));
    }

    /**
     * 获取没有被某个子集选中的文章
     *
     * @param pageAdminDTO
     * @return
     */
    public Page<DaoSchoolChildMaterialNotPageAdminVO> selectByNotChildIdPageList(DaoSchoolMaterialNotChildIdPageListDTO pageAdminDTO) {
        return baseMapper.selectByNotChildIdPageList(pageAdminDTO.toMp(), pageAdminDTO);
    }

    /**
     * 素材关联新增
     *
     * @param info
     * @return
     */
    public Boolean saveAdmin(List<DaoSchoolMaterialChildSaveAdminDTO> info) {
        List<DaoSchoolChildMaterial> list = new ArrayList<>();
        info.forEach(dto -> {
            DaoSchoolChildMaterial daoSchoolChildMaterial = new DaoSchoolChildMaterial();
            BeanUtil.copyProperties(dto, daoSchoolChildMaterial);
            daoSchoolChildMaterial.setCreateId(SysMemberPool.getMember().getId());
            daoSchoolChildMaterial.setModifyId(SysMemberPool.getMember().getId());
            list.add(daoSchoolChildMaterial);
        });
        return SqlHelper.retBool(baseMapper.saveAdmin(list));
    }

    /**
     * 获取子集下的素材
     *
     * @param dto
     * @return
     */
    public Page<DaoSchoolChildMaterialPageVO> getChildMaterialList(DaoSchoolHomeArticleListDTO dto) {
        return baseMapper.getChildMaterialList(dto.toMp(), dto,6L);
    }

    /**
     * 修改排序
     *
     * @param dto
     * @return
     */
    public Boolean updateSortById(DaoSchoolChildMaterialUpdateSortAdminDTO dto) {

        return baseMapper.updateSortById(dto);
    }

}
